home *** CD-ROM | disk | FTP | other *** search
/ One Click 11 / OneClick11.iso / Bancos de Dados / Conversao / Mysql2Excel / Setup.exe / Mysql2Excel.exe / locale.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-06-23  |  20.7 KB  |  720 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. """ Locale support.
  5.  
  6.     The module provides low-level access to the C lib's locale APIs
  7.     and adds high level number formatting APIs as well as a locale
  8.     aliasing engine to complement these.
  9.  
  10.     The aliasing engine includes support for many commonly used locale
  11.     names and maps them to values suitable for passing to the C lib's
  12.     setlocale() function. It also includes default encodings for all
  13.     supported locale names.
  14.  
  15. """
  16. import sys
  17. __all__ = [
  18.     'setlocale',
  19.     'Error',
  20.     'localeconv',
  21.     'strcoll',
  22.     'strxfrm',
  23.     'format',
  24.     'str',
  25.     'atof',
  26.     'atoi',
  27.     'LC_CTYPE',
  28.     'LC_COLLATE',
  29.     'LC_TIME',
  30.     'LC_MONETARY',
  31.     'LC_NUMERIC',
  32.     'LC_ALL',
  33.     'CHAR_MAX']
  34.  
  35. try:
  36.     from _locale import *
  37. except ImportError:
  38.     CHAR_MAX = 127
  39.     LC_ALL = 6
  40.     LC_COLLATE = 3
  41.     LC_CTYPE = 0
  42.     LC_MESSAGES = 5
  43.     LC_MONETARY = 4
  44.     LC_NUMERIC = 1
  45.     LC_TIME = 2
  46.     Error = ValueError
  47.     
  48.     def localeconv():
  49.         ''' localeconv() -> dict.
  50.             Returns numeric and monetary locale-specific parameters.
  51.         '''
  52.         return {
  53.             'grouping': [
  54.                 127],
  55.             'currency_symbol': '',
  56.             'n_sign_posn': 127,
  57.             'p_cs_precedes': 127,
  58.             'n_cs_precedes': 127,
  59.             'mon_grouping': [],
  60.             'n_sep_by_space': 127,
  61.             'decimal_point': '.',
  62.             'negative_sign': '',
  63.             'positive_sign': '',
  64.             'p_sep_by_space': 127,
  65.             'int_curr_symbol': '',
  66.             'p_sign_posn': 127,
  67.             'thousands_sep': '',
  68.             'mon_thousands_sep': '',
  69.             'frac_digits': 127,
  70.             'mon_decimal_point': '',
  71.             'int_frac_digits': 127 }
  72.  
  73.     
  74.     def setlocale(category, value = None):
  75.         ''' setlocale(integer,string=None) -> string.
  76.             Activates/queries locale processing.
  77.         '''
  78.         if value is not None and value != 'C':
  79.             raise Error, '_locale emulation only supports "C" locale'
  80.         
  81.         return 'C'
  82.  
  83.     
  84.     def strcoll(a, b):
  85.         ''' strcoll(string,string) -> int.
  86.             Compares two strings according to the locale.
  87.         '''
  88.         return cmp(a, b)
  89.  
  90.     
  91.     def strxfrm(s):
  92.         ''' strxfrm(string) -> string.
  93.             Returns a string that behaves for cmp locale-aware.
  94.         '''
  95.         return s
  96.  
  97.  
  98.  
  99. def _group(s):
  100.     conv = localeconv()
  101.     grouping = conv['grouping']
  102.     if not grouping:
  103.         return (s, 0)
  104.     
  105.     result = ''
  106.     seps = 0
  107.     spaces = ''
  108.     if s[-1] == ' ':
  109.         sp = s.find(' ')
  110.         spaces = s[sp:]
  111.         s = s[:sp]
  112.     
  113.     while s and grouping:
  114.         if grouping[0] == CHAR_MAX:
  115.             break
  116.         elif grouping[0] != 0:
  117.             group = grouping[0]
  118.             grouping = grouping[1:]
  119.         
  120.         if result:
  121.             result = s[-group:] + conv['thousands_sep'] + result
  122.             seps += 1
  123.         else:
  124.             result = s[-group:]
  125.         s = s[:-group]
  126.         if s and s[-1] not in '0123456789':
  127.             return (s + result + spaces, seps)
  128.         
  129.     if not result:
  130.         return (s + spaces, seps)
  131.     
  132.     if s:
  133.         result = s + conv['thousands_sep'] + result
  134.         seps += 1
  135.     
  136.     return (result + spaces, seps)
  137.  
  138.  
  139. def format(f, val, grouping = 0):
  140.     '''Formats a value in the same way that the % formatting would use,
  141.     but takes the current locale into account.
  142.     Grouping is applied if the third parameter is true.'''
  143.     result = f % val
  144.     fields = result.split('.')
  145.     seps = 0
  146.     if grouping:
  147.         (fields[0], seps) = _group(fields[0])
  148.     
  149.     if len(fields) == 2:
  150.         result = fields[0] + localeconv()['decimal_point'] + fields[1]
  151.     elif len(fields) == 1:
  152.         result = fields[0]
  153.     else:
  154.         raise Error, 'Too many decimal points in result string'
  155.     while seps:
  156.         sp = result.find(' ')
  157.         if sp == -1:
  158.             break
  159.         
  160.         result = result[:sp] + result[sp + 1:]
  161.         seps -= 1
  162.     return result
  163.  
  164.  
  165. def str(val):
  166.     '''Convert float to integer, taking the locale into account.'''
  167.     return format('%.12g', val)
  168.  
  169.  
  170. def atof(str, func = float):
  171.     '''Parses a string as a float according to the locale settings.'''
  172.     ts = localeconv()['thousands_sep']
  173.     if ts:
  174.         s = str.split(ts)
  175.         str = ''.join(s)
  176.     
  177.     dd = localeconv()['decimal_point']
  178.     if dd:
  179.         s = str.split(dd)
  180.         str = '.'.join(s)
  181.     
  182.     return func(str)
  183.  
  184.  
  185. def atoi(str):
  186.     '''Converts a string to an integer according to the locale settings.'''
  187.     return atof(str, int)
  188.  
  189.  
  190. def _test():
  191.     setlocale(LC_ALL, '')
  192.     s1 = format('%d', 123456789, 1)
  193.     print s1, 'is', atoi(s1)
  194.     s1 = str(3.1400000000000001)
  195.     print s1, 'is', atof(s1)
  196.  
  197. _setlocale = setlocale
  198.  
  199. def normalize(localename):
  200.     ''' Returns a normalized locale code for the given locale
  201.         name.
  202.  
  203.         The returned locale code is formatted for use with
  204.         setlocale().
  205.  
  206.         If normalization fails, the original name is returned
  207.         unchanged.
  208.  
  209.         If the given encoding is not known, the function defaults to
  210.         the default encoding for the locale code just like setlocale()
  211.         does.
  212.  
  213.     '''
  214.     fullname = localename.lower()
  215.     if ':' in fullname:
  216.         fullname = fullname.replace(':', '.')
  217.     
  218.     if '.' in fullname:
  219.         (langname, encoding) = fullname.split('.')[:2]
  220.         fullname = langname + '.' + encoding
  221.     else:
  222.         langname = fullname
  223.         encoding = ''
  224.     code = locale_alias.get(fullname, None)
  225.     if code is not None:
  226.         return code
  227.     
  228.     code = locale_alias.get(langname, None)
  229.     if code is not None:
  230.         if '.' in code:
  231.             (langname, defenc) = code.split('.')
  232.         else:
  233.             langname = code
  234.             defenc = ''
  235.         if encoding:
  236.             encoding = encoding_alias.get(encoding, encoding)
  237.         else:
  238.             encoding = defenc
  239.         if encoding:
  240.             return langname + '.' + encoding
  241.         else:
  242.             return langname
  243.     else:
  244.         return localename
  245.  
  246.  
  247. def _parse_localename(localename):
  248.     ''' Parses the locale code for localename and returns the
  249.         result as tuple (language code, encoding).
  250.  
  251.         The localename is normalized and passed through the locale
  252.         alias engine. A ValueError is raised in case the locale name
  253.         cannot be parsed.
  254.  
  255.         The language code corresponds to RFC 1766.  code and encoding
  256.         can be None in case the values cannot be determined or are
  257.         unknown to this implementation.
  258.  
  259.     '''
  260.     code = normalize(localename)
  261.     if '.' in code:
  262.         return code.split('.')[:2]
  263.     elif code == 'C':
  264.         return (None, None)
  265.     
  266.     raise ValueError, 'unknown locale: %s' % localename
  267.  
  268.  
  269. def _build_localename(localetuple):
  270.     ''' Builds a locale code from the given tuple (language code,
  271.         encoding).
  272.  
  273.         No aliasing or normalizing takes place.
  274.  
  275.     '''
  276.     (language, encoding) = localetuple
  277.     if language is None:
  278.         language = 'C'
  279.     
  280.     if encoding is None:
  281.         return language
  282.     else:
  283.         return language + '.' + encoding
  284.  
  285.  
  286. def getdefaultlocale(envvars = ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG')):
  287.     ''' Tries to determine the default locale settings and returns
  288.         them as tuple (language code, encoding).
  289.  
  290.         According to POSIX, a program which has not called
  291.         setlocale(LC_ALL, "") runs using the portable \'C\' locale.
  292.         Calling setlocale(LC_ALL, "") lets it use the default locale as
  293.         defined by the LANG variable. Since we don\'t want to interfere
  294.         with the current locale setting we thus emulate the behavior
  295.         in the way described above.
  296.  
  297.         To maintain compatibility with other platforms, not only the
  298.         LANG variable is tested, but a list of variables given as
  299.         envvars parameter. The first found to be defined will be
  300.         used. envvars defaults to the search path used in GNU gettext;
  301.         it must always contain the variable name \'LANG\'.
  302.  
  303.         Except for the code \'C\', the language code corresponds to RFC
  304.         1766.  code and encoding can be None in case the values cannot
  305.         be determined.
  306.  
  307.     '''
  308.     
  309.     try:
  310.         import _locale
  311.         (code, encoding) = _locale._getdefaultlocale()
  312.     except (ImportError, AttributeError):
  313.         pass
  314.  
  315.     if sys.platform == 'win32' and code and code[:2] == '0x':
  316.         code = windows_locale.get(int(code, 0))
  317.     
  318.     return (code, encoding)
  319.     import os
  320.     lookup = os.environ.get
  321.     for variable in envvars:
  322.         localename = lookup(variable, None)
  323.         if localename is not None:
  324.             break
  325.         
  326.     else:
  327.         localename = 'C'
  328.     return _parse_localename(localename)
  329.  
  330.  
  331. def getlocale(category = LC_CTYPE):
  332.     """ Returns the current setting for the given locale category as
  333.         tuple (language code, encoding).
  334.  
  335.         category may be one of the LC_* value except LC_ALL. It
  336.         defaults to LC_CTYPE.
  337.  
  338.         Except for the code 'C', the language code corresponds to RFC
  339.         1766.  code and encoding can be None in case the values cannot
  340.         be determined.
  341.  
  342.     """
  343.     localename = _setlocale(category)
  344.     if category == LC_ALL and ';' in localename:
  345.         raise TypeError, 'category LC_ALL is not supported'
  346.     
  347.     return _parse_localename(localename)
  348.  
  349.  
  350. def setlocale(category, locale = None):
  351.     ''' Set the locale for the given category.  The locale can be
  352.         a string, a locale tuple (language code, encoding), or None.
  353.  
  354.         Locale tuples are converted to strings the locale aliasing
  355.         engine.  Locale strings are passed directly to the C lib.
  356.  
  357.         category may be given as one of the LC_* values.
  358.  
  359.     '''
  360.     if locale and type(locale) is not type(''):
  361.         locale = normalize(_build_localename(locale))
  362.     
  363.     return _setlocale(category, locale)
  364.  
  365.  
  366. def resetlocale(category = LC_ALL):
  367.     ''' Sets the locale for category to the default setting.
  368.  
  369.         The default setting is determined by calling
  370.         getdefaultlocale(). category defaults to LC_ALL.
  371.  
  372.     '''
  373.     _setlocale(category, _build_localename(getdefaultlocale()))
  374.  
  375. encoding_alias = {
  376.     '437': 'C',
  377.     'c': 'C',
  378.     'iso8859': 'ISO8859-1',
  379.     '8859': 'ISO8859-1',
  380.     '88591': 'ISO8859-1',
  381.     'ascii': 'ISO8859-1',
  382.     'en': 'ISO8859-1',
  383.     'iso88591': 'ISO8859-1',
  384.     'iso_8859-1': 'ISO8859-1',
  385.     '885915': 'ISO8859-15',
  386.     'iso885915': 'ISO8859-15',
  387.     'iso_8859-15': 'ISO8859-15',
  388.     'iso8859-2': 'ISO8859-2',
  389.     'iso88592': 'ISO8859-2',
  390.     'iso_8859-2': 'ISO8859-2',
  391.     'iso88595': 'ISO8859-5',
  392.     'iso88596': 'ISO8859-6',
  393.     'iso88597': 'ISO8859-7',
  394.     'iso88598': 'ISO8859-8',
  395.     'iso88599': 'ISO8859-9',
  396.     'iso-2022-jp': 'JIS7',
  397.     'jis': 'JIS7',
  398.     'jis7': 'JIS7',
  399.     'sjis': 'SJIS',
  400.     'tis620': 'TACTIS',
  401.     'ajec': 'eucJP',
  402.     'eucjp': 'eucJP',
  403.     'ujis': 'eucJP',
  404.     'utf-8': 'utf',
  405.     'utf8': 'utf',
  406.     'utf8@ucs4': 'utf' }
  407. locale_alias = {
  408.     'american': 'en_US.ISO8859-1',
  409.     'ar': 'ar_AA.ISO8859-6',
  410.     'ar_aa': 'ar_AA.ISO8859-6',
  411.     'ar_sa': 'ar_SA.ISO8859-6',
  412.     'arabic': 'ar_AA.ISO8859-6',
  413.     'bg': 'bg_BG.ISO8859-5',
  414.     'bg_bg': 'bg_BG.ISO8859-5',
  415.     'bulgarian': 'bg_BG.ISO8859-5',
  416.     'c-french': 'fr_CA.ISO8859-1',
  417.     'c': 'C',
  418.     'c_c': 'C',
  419.     'cextend': 'en_US.ISO8859-1',
  420.     'chinese-s': 'zh_CN.eucCN',
  421.     'chinese-t': 'zh_TW.eucTW',
  422.     'croatian': 'hr_HR.ISO8859-2',
  423.     'cs': 'cs_CZ.ISO8859-2',
  424.     'cs_cs': 'cs_CZ.ISO8859-2',
  425.     'cs_cz': 'cs_CZ.ISO8859-2',
  426.     'cz': 'cz_CZ.ISO8859-2',
  427.     'cz_cz': 'cz_CZ.ISO8859-2',
  428.     'czech': 'cs_CS.ISO8859-2',
  429.     'da': 'da_DK.ISO8859-1',
  430.     'da_dk': 'da_DK.ISO8859-1',
  431.     'danish': 'da_DK.ISO8859-1',
  432.     'de': 'de_DE.ISO8859-1',
  433.     'de_at': 'de_AT.ISO8859-1',
  434.     'de_ch': 'de_CH.ISO8859-1',
  435.     'de_de': 'de_DE.ISO8859-1',
  436.     'dutch': 'nl_BE.ISO8859-1',
  437.     'ee': 'ee_EE.ISO8859-4',
  438.     'el': 'el_GR.ISO8859-7',
  439.     'el_gr': 'el_GR.ISO8859-7',
  440.     'en': 'en_US.ISO8859-1',
  441.     'en_au': 'en_AU.ISO8859-1',
  442.     'en_ca': 'en_CA.ISO8859-1',
  443.     'en_gb': 'en_GB.ISO8859-1',
  444.     'en_ie': 'en_IE.ISO8859-1',
  445.     'en_nz': 'en_NZ.ISO8859-1',
  446.     'en_uk': 'en_GB.ISO8859-1',
  447.     'en_us': 'en_US.ISO8859-1',
  448.     'eng_gb': 'en_GB.ISO8859-1',
  449.     'english': 'en_EN.ISO8859-1',
  450.     'english_uk': 'en_GB.ISO8859-1',
  451.     'english_united-states': 'en_US.ISO8859-1',
  452.     'english_us': 'en_US.ISO8859-1',
  453.     'es': 'es_ES.ISO8859-1',
  454.     'es_ar': 'es_AR.ISO8859-1',
  455.     'es_bo': 'es_BO.ISO8859-1',
  456.     'es_cl': 'es_CL.ISO8859-1',
  457.     'es_co': 'es_CO.ISO8859-1',
  458.     'es_cr': 'es_CR.ISO8859-1',
  459.     'es_ec': 'es_EC.ISO8859-1',
  460.     'es_es': 'es_ES.ISO8859-1',
  461.     'es_gt': 'es_GT.ISO8859-1',
  462.     'es_mx': 'es_MX.ISO8859-1',
  463.     'es_ni': 'es_NI.ISO8859-1',
  464.     'es_pa': 'es_PA.ISO8859-1',
  465.     'es_pe': 'es_PE.ISO8859-1',
  466.     'es_py': 'es_PY.ISO8859-1',
  467.     'es_sv': 'es_SV.ISO8859-1',
  468.     'es_uy': 'es_UY.ISO8859-1',
  469.     'es_ve': 'es_VE.ISO8859-1',
  470.     'et': 'et_EE.ISO8859-4',
  471.     'et_ee': 'et_EE.ISO8859-4',
  472.     'fi': 'fi_FI.ISO8859-1',
  473.     'fi_fi': 'fi_FI.ISO8859-1',
  474.     'finnish': 'fi_FI.ISO8859-1',
  475.     'fr': 'fr_FR.ISO8859-1',
  476.     'fr_be': 'fr_BE.ISO8859-1',
  477.     'fr_ca': 'fr_CA.ISO8859-1',
  478.     'fr_ch': 'fr_CH.ISO8859-1',
  479.     'fr_fr': 'fr_FR.ISO8859-1',
  480.     'fre_fr': 'fr_FR.ISO8859-1',
  481.     'french': 'fr_FR.ISO8859-1',
  482.     'french_france': 'fr_FR.ISO8859-1',
  483.     'ger_de': 'de_DE.ISO8859-1',
  484.     'german': 'de_DE.ISO8859-1',
  485.     'german_germany': 'de_DE.ISO8859-1',
  486.     'greek': 'el_GR.ISO8859-7',
  487.     'hebrew': 'iw_IL.ISO8859-8',
  488.     'hr': 'hr_HR.ISO8859-2',
  489.     'hr_hr': 'hr_HR.ISO8859-2',
  490.     'hu': 'hu_HU.ISO8859-2',
  491.     'hu_hu': 'hu_HU.ISO8859-2',
  492.     'hungarian': 'hu_HU.ISO8859-2',
  493.     'icelandic': 'is_IS.ISO8859-1',
  494.     'id': 'id_ID.ISO8859-1',
  495.     'id_id': 'id_ID.ISO8859-1',
  496.     'is': 'is_IS.ISO8859-1',
  497.     'is_is': 'is_IS.ISO8859-1',
  498.     'iso-8859-1': 'en_US.ISO8859-1',
  499.     'iso-8859-15': 'en_US.ISO8859-15',
  500.     'iso8859-1': 'en_US.ISO8859-1',
  501.     'iso8859-15': 'en_US.ISO8859-15',
  502.     'iso_8859_1': 'en_US.ISO8859-1',
  503.     'iso_8859_15': 'en_US.ISO8859-15',
  504.     'it': 'it_IT.ISO8859-1',
  505.     'it_ch': 'it_CH.ISO8859-1',
  506.     'it_it': 'it_IT.ISO8859-1',
  507.     'italian': 'it_IT.ISO8859-1',
  508.     'iw': 'iw_IL.ISO8859-8',
  509.     'iw_il': 'iw_IL.ISO8859-8',
  510.     'ja': 'ja_JP.eucJP',
  511.     'ja.jis': 'ja_JP.JIS7',
  512.     'ja.sjis': 'ja_JP.SJIS',
  513.     'ja_jp': 'ja_JP.eucJP',
  514.     'ja_jp.ajec': 'ja_JP.eucJP',
  515.     'ja_jp.euc': 'ja_JP.eucJP',
  516.     'ja_jp.eucjp': 'ja_JP.eucJP',
  517.     'ja_jp.iso-2022-jp': 'ja_JP.JIS7',
  518.     'ja_jp.jis': 'ja_JP.JIS7',
  519.     'ja_jp.jis7': 'ja_JP.JIS7',
  520.     'ja_jp.mscode': 'ja_JP.SJIS',
  521.     'ja_jp.sjis': 'ja_JP.SJIS',
  522.     'ja_jp.ujis': 'ja_JP.eucJP',
  523.     'japan': 'ja_JP.eucJP',
  524.     'japanese': 'ja_JP.SJIS',
  525.     'japanese-euc': 'ja_JP.eucJP',
  526.     'japanese.euc': 'ja_JP.eucJP',
  527.     'jp_jp': 'ja_JP.eucJP',
  528.     'ko': 'ko_KR.eucKR',
  529.     'ko_kr': 'ko_KR.eucKR',
  530.     'ko_kr.euc': 'ko_KR.eucKR',
  531.     'korean': 'ko_KR.eucKR',
  532.     'lt': 'lt_LT.ISO8859-4',
  533.     'lv': 'lv_LV.ISO8859-4',
  534.     'mk': 'mk_MK.ISO8859-5',
  535.     'mk_mk': 'mk_MK.ISO8859-5',
  536.     'nl': 'nl_NL.ISO8859-1',
  537.     'nl_be': 'nl_BE.ISO8859-1',
  538.     'nl_nl': 'nl_NL.ISO8859-1',
  539.     'no': 'no_NO.ISO8859-1',
  540.     'no_no': 'no_NO.ISO8859-1',
  541.     'norwegian': 'no_NO.ISO8859-1',
  542.     'pl': 'pl_PL.ISO8859-2',
  543.     'pl_pl': 'pl_PL.ISO8859-2',
  544.     'polish': 'pl_PL.ISO8859-2',
  545.     'portuguese': 'pt_PT.ISO8859-1',
  546.     'portuguese_brazil': 'pt_BR.ISO8859-1',
  547.     'posix': 'C',
  548.     'posix-utf2': 'C',
  549.     'pt': 'pt_PT.ISO8859-1',
  550.     'pt_br': 'pt_BR.ISO8859-1',
  551.     'pt_pt': 'pt_PT.ISO8859-1',
  552.     'ro': 'ro_RO.ISO8859-2',
  553.     'ro_ro': 'ro_RO.ISO8859-2',
  554.     'ru': 'ru_RU.ISO8859-5',
  555.     'ru_ru': 'ru_RU.ISO8859-5',
  556.     'rumanian': 'ro_RO.ISO8859-2',
  557.     'russian': 'ru_RU.ISO8859-5',
  558.     'serbocroatian': 'sh_YU.ISO8859-2',
  559.     'sh': 'sh_YU.ISO8859-2',
  560.     'sh_hr': 'sh_HR.ISO8859-2',
  561.     'sh_sp': 'sh_YU.ISO8859-2',
  562.     'sh_yu': 'sh_YU.ISO8859-2',
  563.     'sk': 'sk_SK.ISO8859-2',
  564.     'sk_sk': 'sk_SK.ISO8859-2',
  565.     'sl': 'sl_CS.ISO8859-2',
  566.     'sl_cs': 'sl_CS.ISO8859-2',
  567.     'sl_si': 'sl_SI.ISO8859-2',
  568.     'slovak': 'sk_SK.ISO8859-2',
  569.     'slovene': 'sl_CS.ISO8859-2',
  570.     'sp': 'sp_YU.ISO8859-5',
  571.     'sp_yu': 'sp_YU.ISO8859-5',
  572.     'spanish': 'es_ES.ISO8859-1',
  573.     'spanish_spain': 'es_ES.ISO8859-1',
  574.     'sr_sp': 'sr_SP.ISO8859-2',
  575.     'sv': 'sv_SE.ISO8859-1',
  576.     'sv_se': 'sv_SE.ISO8859-1',
  577.     'swedish': 'sv_SE.ISO8859-1',
  578.     'th_th': 'th_TH.TACTIS',
  579.     'tr': 'tr_TR.ISO8859-9',
  580.     'tr_tr': 'tr_TR.ISO8859-9',
  581.     'turkish': 'tr_TR.ISO8859-9',
  582.     'univ': 'en_US.utf',
  583.     'universal': 'en_US.utf',
  584.     'zh': 'zh_CN.eucCN',
  585.     'zh_cn': 'zh_CN.eucCN',
  586.     'zh_cn.big5': 'zh_TW.eucTW',
  587.     'zh_cn.euc': 'zh_CN.eucCN',
  588.     'zh_tw': 'zh_TW.eucTW',
  589.     'zh_tw.euc': 'zh_TW.eucTW' }
  590. windows_locale = {
  591.     1028: 'zh_TW',
  592.     2052: 'zh_CN',
  593.     1030: 'da_DK',
  594.     1043: 'nl_NL',
  595.     1033: 'en_US',
  596.     2057: 'en_UK',
  597.     3081: 'en_AU',
  598.     4105: 'en_CA',
  599.     5129: 'en_NZ',
  600.     6153: 'en_IE',
  601.     7177: 'en_ZA',
  602.     1035: 'fi_FI',
  603.     1036: 'fr_FR',
  604.     2060: 'fr_BE',
  605.     3084: 'fr_CA',
  606.     4108: 'fr_CH',
  607.     1031: 'de_DE',
  608.     1032: 'el_GR',
  609.     1037: 'iw_IL',
  610.     1039: 'is_IS',
  611.     1040: 'it_IT',
  612.     1041: 'ja_JA',
  613.     1044: 'no_NO',
  614.     2070: 'pt_PT',
  615.     3082: 'es_ES',
  616.     1089: 'sw_KE',
  617.     1053: 'sv_SE',
  618.     2077: 'sv_FI',
  619.     1055: 'tr_TR' }
  620.  
  621. def _print_locale():
  622.     ''' Test function.
  623.     '''
  624.     categories = { }
  625.     
  626.     def _init_categories(categories = categories):
  627.         for k, v in globals().items():
  628.             if k[:3] == 'LC_':
  629.                 categories[k] = v
  630.             
  631.         
  632.  
  633.     _init_categories()
  634.     del categories['LC_ALL']
  635.     print 'Locale defaults as determined by getdefaultlocale():'
  636.     print '-' * 72
  637.     (lang, enc) = getdefaultlocale()
  638.     print 'Language: ',
  639.     if not lang:
  640.         pass
  641.     print '(undefined)'
  642.     print 'Encoding: ',
  643.     if not enc:
  644.         pass
  645.     print '(undefined)'
  646.     print 
  647.     print 'Locale settings on startup:'
  648.     print '-' * 72
  649.     for name, category in categories.items():
  650.         print name, '...'
  651.         (lang, enc) = getlocale(category)
  652.         print '   Language: ',
  653.         if not lang:
  654.             pass
  655.         print '(undefined)'
  656.         print '   Encoding: ',
  657.         if not enc:
  658.             pass
  659.         print '(undefined)'
  660.         print 
  661.     
  662.     print 
  663.     print 'Locale settings after calling resetlocale():'
  664.     print '-' * 72
  665.     resetlocale()
  666.     for name, category in categories.items():
  667.         print name, '...'
  668.         (lang, enc) = getlocale(category)
  669.         print '   Language: ',
  670.         if not lang:
  671.             pass
  672.         print '(undefined)'
  673.         print '   Encoding: ',
  674.         if not enc:
  675.             pass
  676.         print '(undefined)'
  677.         print 
  678.     
  679.     
  680.     try:
  681.         setlocale(LC_ALL, '')
  682.     except:
  683.         print 'NOTE:'
  684.         print 'setlocale(LC_ALL, "") does not support the default locale'
  685.         print 'given in the OS environment variables.'
  686.  
  687.     print 
  688.     print 'Locale settings after calling setlocale(LC_ALL, ""):'
  689.     print '-' * 72
  690.     for name, category in categories.items():
  691.         print name, '...'
  692.         (lang, enc) = getlocale(category)
  693.         print '   Language: ',
  694.         if not lang:
  695.             pass
  696.         print '(undefined)'
  697.         print '   Encoding: ',
  698.         if not enc:
  699.             pass
  700.         print '(undefined)'
  701.         print 
  702.     
  703.  
  704.  
  705. try:
  706.     LC_MESSAGES
  707. except:
  708.     pass
  709.  
  710. __all__.append('LC_MESSAGES')
  711. if __name__ == '__main__':
  712.     print 'Locale aliasing:'
  713.     print 
  714.     _print_locale()
  715.     print 
  716.     print 'Number formatting:'
  717.     print 
  718.     _test()
  719.  
  720.